/******************************************************************************* 
 *  Copyright 2007 Amazon Technologies, Inc.  
 *  Licensed under the Apache License, Version 2.0 (the "License"); 
 *  
 *  You may not use this file except in compliance with the License. 
 *  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
 *  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR 
 *  CONDITIONS OF ANY KIND, either express or implied. See the License for the 
 *  specific language governing permissions and limitations under the License.
 * ***************************************************************************** 
 *    __  _    _  ___ 
 *   (  )( \/\/ )/ __)
 *   /__\ \    / \__ \
 *  (_)(_) \/\/  (___/
 * 
 *  Amazon ECS CSharp Library
 *  API Version: 2007-07-16
 *  Generated: Thu Aug 02 10:15:38 PDT 2007 
 * 
 */

using System;
using System.Xml.Serialization;
using System.Collections.Generic;
using System.Text;


namespace Amazon.ECS.Model
{
    [XmlTypeAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16")]
    [XmlRootAttribute(Namespace = "http://webservices.amazon.com/AWSECommerceService/2007-07-16", IsNullable = false)]
    public class Cart
    {
    
        private String cartIdField;

        private String HMACField;

        private String URLEncodedHMACField;

        private String purchaseURLField;

        private  Price subTotalField;
        private  CartItems cartItemsField;
        private  SavedForLaterItems savedForLaterItemsField;
        private  SimilarProducts similarProductsField;
        private  TopSellers topSellersField;
        private  NewReleases newReleasesField;
        private  SimilarViewedProducts similarViewedProductsField;
        private  OtherCategoriesSimilarProducts otherCategoriesSimilarProductsField;

        /// <summary>
        /// Gets and sets the CartId property.
        /// </summary>
        [XmlElementAttribute(ElementName = "CartId")]
        public String CartId
        {
            get { return this.cartIdField ; }
            set { this.cartIdField= value; }
        }



        /// <summary>
        /// Sets the CartId property
        /// </summary>
        /// <param name="cartId">CartId property</param>
        /// <returns>this instance</returns>
        public Cart WithCartId(String cartId)
        {
            this.cartIdField = cartId;
            return this;
        }



        /// <summary>
        /// Checks if CartId property is set
        /// </summary>
        /// <returns>true if CartId property is set</returns>
        public Boolean IsSetCartId()
        {
            return  this.cartIdField != null;

        }


        /// <summary>
        /// Gets and sets the HMAC property.
        /// </summary>
        [XmlElementAttribute(ElementName = "HMAC")]
        public String HMAC
        {
            get { return this.HMACField ; }
            set { this.HMACField= value; }
        }



        /// <summary>
        /// Sets the HMAC property
        /// </summary>
        /// <param name="HMAC">HMAC property</param>
        /// <returns>this instance</returns>
        public Cart WithHMAC(String HMAC)
        {
            this.HMACField = HMAC;
            return this;
        }



        /// <summary>
        /// Checks if HMAC property is set
        /// </summary>
        /// <returns>true if HMAC property is set</returns>
        public Boolean IsSetHMAC()
        {
            return  this.HMACField != null;

        }


        /// <summary>
        /// Gets and sets the URLEncodedHMAC property.
        /// </summary>
        [XmlElementAttribute(ElementName = "URLEncodedHMAC")]
        public String URLEncodedHMAC
        {
            get { return this.URLEncodedHMACField ; }
            set { this.URLEncodedHMACField= value; }
        }



        /// <summary>
        /// Sets the URLEncodedHMAC property
        /// </summary>
        /// <param name="URLEncodedHMAC">URLEncodedHMAC property</param>
        /// <returns>this instance</returns>
        public Cart WithURLEncodedHMAC(String URLEncodedHMAC)
        {
            this.URLEncodedHMACField = URLEncodedHMAC;
            return this;
        }



        /// <summary>
        /// Checks if URLEncodedHMAC property is set
        /// </summary>
        /// <returns>true if URLEncodedHMAC property is set</returns>
        public Boolean IsSetURLEncodedHMAC()
        {
            return  this.URLEncodedHMACField != null;

        }


        /// <summary>
        /// Gets and sets the PurchaseURL property.
        /// </summary>
        [XmlElementAttribute(ElementName = "PurchaseURL")]
        public String PurchaseURL
        {
            get { return this.purchaseURLField ; }
            set { this.purchaseURLField= value; }
        }



        /// <summary>
        /// Sets the PurchaseURL property
        /// </summary>
        /// <param name="purchaseURL">PurchaseURL property</param>
        /// <returns>this instance</returns>
        public Cart WithPurchaseURL(String purchaseURL)
        {
            this.purchaseURLField = purchaseURL;
            return this;
        }



        /// <summary>
        /// Checks if PurchaseURL property is set
        /// </summary>
        /// <returns>true if PurchaseURL property is set</returns>
        public Boolean IsSetPurchaseURL()
        {
            return  this.purchaseURLField != null;

        }


        /// <summary>
        /// Gets and sets the SubTotal property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SubTotal")]
        public Price SubTotal
        {
            get { return this.subTotalField ; }
            set { this.subTotalField = value; }
        }



        /// <summary>
        /// Sets the SubTotal property
        /// </summary>
        /// <param name="subTotal">SubTotal property</param>
        /// <returns>this instance</returns>
        public Cart WithSubTotal(Price subTotal)
        {
            this.subTotalField = subTotal;
            return this;
        }



        /// <summary>
        /// Checks if SubTotal property is set
        /// </summary>
        /// <returns>true if SubTotal property is set</returns>
        public Boolean IsSetSubTotal()
        {
            return this.subTotalField != null;
        }




        /// <summary>
        /// Gets and sets the CartItems property.
        /// </summary>
        [XmlElementAttribute(ElementName = "CartItems")]
        public CartItems CartItems
        {
            get { return this.cartItemsField ; }
            set { this.cartItemsField = value; }
        }



        /// <summary>
        /// Sets the CartItems property
        /// </summary>
        /// <param name="cartItems">CartItems property</param>
        /// <returns>this instance</returns>
        public Cart WithCartItems(CartItems cartItems)
        {
            this.cartItemsField = cartItems;
            return this;
        }



        /// <summary>
        /// Checks if CartItems property is set
        /// </summary>
        /// <returns>true if CartItems property is set</returns>
        public Boolean IsSetCartItems()
        {
            return this.cartItemsField != null;
        }




        /// <summary>
        /// Gets and sets the SavedForLaterItems property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SavedForLaterItems")]
        public SavedForLaterItems SavedForLaterItems
        {
            get { return this.savedForLaterItemsField ; }
            set { this.savedForLaterItemsField = value; }
        }



        /// <summary>
        /// Sets the SavedForLaterItems property
        /// </summary>
        /// <param name="savedForLaterItems">SavedForLaterItems property</param>
        /// <returns>this instance</returns>
        public Cart WithSavedForLaterItems(SavedForLaterItems savedForLaterItems)
        {
            this.savedForLaterItemsField = savedForLaterItems;
            return this;
        }



        /// <summary>
        /// Checks if SavedForLaterItems property is set
        /// </summary>
        /// <returns>true if SavedForLaterItems property is set</returns>
        public Boolean IsSetSavedForLaterItems()
        {
            return this.savedForLaterItemsField != null;
        }




        /// <summary>
        /// Gets and sets the SimilarProducts property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SimilarProducts")]
        public SimilarProducts SimilarProducts
        {
            get { return this.similarProductsField ; }
            set { this.similarProductsField = value; }
        }



        /// <summary>
        /// Sets the SimilarProducts property
        /// </summary>
        /// <param name="similarProducts">SimilarProducts property</param>
        /// <returns>this instance</returns>
        public Cart WithSimilarProducts(SimilarProducts similarProducts)
        {
            this.similarProductsField = similarProducts;
            return this;
        }



        /// <summary>
        /// Checks if SimilarProducts property is set
        /// </summary>
        /// <returns>true if SimilarProducts property is set</returns>
        public Boolean IsSetSimilarProducts()
        {
            return this.similarProductsField != null;
        }




        /// <summary>
        /// Gets and sets the TopSellers property.
        /// </summary>
        [XmlElementAttribute(ElementName = "TopSellers")]
        public TopSellers TopSellers
        {
            get { return this.topSellersField ; }
            set { this.topSellersField = value; }
        }



        /// <summary>
        /// Sets the TopSellers property
        /// </summary>
        /// <param name="topSellers">TopSellers property</param>
        /// <returns>this instance</returns>
        public Cart WithTopSellers(TopSellers topSellers)
        {
            this.topSellersField = topSellers;
            return this;
        }



        /// <summary>
        /// Checks if TopSellers property is set
        /// </summary>
        /// <returns>true if TopSellers property is set</returns>
        public Boolean IsSetTopSellers()
        {
            return this.topSellersField != null;
        }




        /// <summary>
        /// Gets and sets the NewReleases property.
        /// </summary>
        [XmlElementAttribute(ElementName = "NewReleases")]
        public NewReleases NewReleases
        {
            get { return this.newReleasesField ; }
            set { this.newReleasesField = value; }
        }



        /// <summary>
        /// Sets the NewReleases property
        /// </summary>
        /// <param name="newReleases">NewReleases property</param>
        /// <returns>this instance</returns>
        public Cart WithNewReleases(NewReleases newReleases)
        {
            this.newReleasesField = newReleases;
            return this;
        }



        /// <summary>
        /// Checks if NewReleases property is set
        /// </summary>
        /// <returns>true if NewReleases property is set</returns>
        public Boolean IsSetNewReleases()
        {
            return this.newReleasesField != null;
        }




        /// <summary>
        /// Gets and sets the SimilarViewedProducts property.
        /// </summary>
        [XmlElementAttribute(ElementName = "SimilarViewedProducts")]
        public SimilarViewedProducts SimilarViewedProducts
        {
            get { return this.similarViewedProductsField ; }
            set { this.similarViewedProductsField = value; }
        }



        /// <summary>
        /// Sets the SimilarViewedProducts property
        /// </summary>
        /// <param name="similarViewedProducts">SimilarViewedProducts property</param>
        /// <returns>this instance</returns>
        public Cart WithSimilarViewedProducts(SimilarViewedProducts similarViewedProducts)
        {
            this.similarViewedProductsField = similarViewedProducts;
            return this;
        }



        /// <summary>
        /// Checks if SimilarViewedProducts property is set
        /// </summary>
        /// <returns>true if SimilarViewedProducts property is set</returns>
        public Boolean IsSetSimilarViewedProducts()
        {
            return this.similarViewedProductsField != null;
        }




        /// <summary>
        /// Gets and sets the OtherCategoriesSimilarProducts property.
        /// </summary>
        [XmlElementAttribute(ElementName = "OtherCategoriesSimilarProducts")]
        public OtherCategoriesSimilarProducts OtherCategoriesSimilarProducts
        {
            get { return this.otherCategoriesSimilarProductsField ; }
            set { this.otherCategoriesSimilarProductsField = value; }
        }



        /// <summary>
        /// Sets the OtherCategoriesSimilarProducts property
        /// </summary>
        /// <param name="otherCategoriesSimilarProducts">OtherCategoriesSimilarProducts property</param>
        /// <returns>this instance</returns>
        public Cart WithOtherCategoriesSimilarProducts(OtherCategoriesSimilarProducts otherCategoriesSimilarProducts)
        {
            this.otherCategoriesSimilarProductsField = otherCategoriesSimilarProducts;
            return this;
        }



        /// <summary>
        /// Checks if OtherCategoriesSimilarProducts property is set
        /// </summary>
        /// <returns>true if OtherCategoriesSimilarProducts property is set</returns>
        public Boolean IsSetOtherCategoriesSimilarProducts()
        {
            return this.otherCategoriesSimilarProductsField != null;
        }






        /// <summary>
        /// XML fragment representation of this object
        /// </summary>
        /// <returns>XML fragment for this object.</returns>
        /// <remarks>
        /// Name for outer tag expected to be set by calling method. 
        /// This fragment returns inner properties representation only
        /// </remarks>


        protected internal String ToXMLFragment() {
            StringBuilder xml = new StringBuilder();
            if (IsSetCartId()) {
                xml.Append("<CartId>");
                xml.Append(EscapeXML(this.CartId));
                xml.Append("</CartId>");
            }
            if (IsSetHMAC()) {
                xml.Append("<HMAC>");
                xml.Append(EscapeXML(this.HMAC));
                xml.Append("</HMAC>");
            }
            if (IsSetURLEncodedHMAC()) {
                xml.Append("<URLEncodedHMAC>");
                xml.Append(EscapeXML(this.URLEncodedHMAC));
                xml.Append("</URLEncodedHMAC>");
            }
            if (IsSetPurchaseURL()) {
                xml.Append("<PurchaseURL>");
                xml.Append(EscapeXML(this.PurchaseURL));
                xml.Append("</PurchaseURL>");
            }
            if (IsSetSubTotal()) {
                Price  subTotal = this.SubTotal;
                xml.Append("<SubTotal>");
                xml.Append(subTotal.ToXMLFragment());
                xml.Append("</SubTotal>");
            } 
            if (IsSetCartItems()) {
                CartItems  cartItems = this.CartItems;
                xml.Append("<CartItems>");
                xml.Append(cartItems.ToXMLFragment());
                xml.Append("</CartItems>");
            } 
            if (IsSetSavedForLaterItems()) {
                SavedForLaterItems  savedForLaterItems = this.SavedForLaterItems;
                xml.Append("<SavedForLaterItems>");
                xml.Append(savedForLaterItems.ToXMLFragment());
                xml.Append("</SavedForLaterItems>");
            } 
            if (IsSetSimilarProducts()) {
                SimilarProducts  similarProducts = this.SimilarProducts;
                xml.Append("<SimilarProducts>");
                xml.Append(similarProducts.ToXMLFragment());
                xml.Append("</SimilarProducts>");
            } 
            if (IsSetTopSellers()) {
                TopSellers  topSellers = this.TopSellers;
                xml.Append("<TopSellers>");
                xml.Append(topSellers.ToXMLFragment());
                xml.Append("</TopSellers>");
            } 
            if (IsSetNewReleases()) {
                NewReleases  newReleases = this.NewReleases;
                xml.Append("<NewReleases>");
                xml.Append(newReleases.ToXMLFragment());
                xml.Append("</NewReleases>");
            } 
            if (IsSetSimilarViewedProducts()) {
                SimilarViewedProducts  similarViewedProducts = this.SimilarViewedProducts;
                xml.Append("<SimilarViewedProducts>");
                xml.Append(similarViewedProducts.ToXMLFragment());
                xml.Append("</SimilarViewedProducts>");
            } 
            if (IsSetOtherCategoriesSimilarProducts()) {
                OtherCategoriesSimilarProducts  otherCategoriesSimilarProducts = this.OtherCategoriesSimilarProducts;
                xml.Append("<OtherCategoriesSimilarProducts>");
                xml.Append(otherCategoriesSimilarProducts.ToXMLFragment());
                xml.Append("</OtherCategoriesSimilarProducts>");
            } 
            return xml.ToString();
        }

        /**
         * 
         * Escape XML special characters
         */
        private String EscapeXML(String str) {
            StringBuilder sb = new StringBuilder();
            foreach (Char c in str)
            {
                switch (c) {
                case '&':
                    sb.Append("&amp;");
                    break;
                case '<':
                    sb.Append("&lt;");
                    break;
                case '>':
                    sb.Append("&gt;");
                    break;
                case '\'':
                    sb.Append("&#039;");
                    break;
                case '"':
                    sb.Append("&quot;");
                    break;
                default:
                    sb.Append(c);
                    break;
                }
            }
            return sb.ToString();
        }




    }

}